package com.project.webapp.action.front;

import java.util.HashMap;
import java.util.Map;

import com.project.dao.bean.Article;
import com.project.service.front.IReadNewService;
import com.project.webapp.action.BaseAction;

/**
 * Course 课程查看详情实作
 * @author Sn
 *
 */
public class ReadNewAction extends BaseAction 
{
	/**
	 * 序列化版本号
	 */
	private static final long serialVersionUID = 1L;
	private IReadNewService iReadNewService;
	// 接受查询到的值
	private Article art = null;
	private String id;

	@Override
	public String execute() throws Exception 
	{
		art = this.transition(iReadNewService.readnew(id));
		return SUCCESS;
	}
	
	//转换得到画面显示资料
	private Article transition(Article art) 
	{
		try 
		{
			//开班类型
			StringBuffer course_type = new StringBuffer();
			int i = 0;
			for (String mm : art.getCourse_type().split("；")) 
			{

				if ("0".equals(mm)) 
				{
					course_type.append(i > 0 ? "、家教" : "家教");
				} else if ("1".equals(mm)) 
				{
					course_type.append(i > 0 ? "、一对一" : "一对一");
				} else if ("2".equals(mm)) 
				{
					course_type.append(i > 0 ? "、小班" : "小班");
				} else if ("3".equals(mm)) 
				{
					course_type.append(i > 0 ? "、大班" : "大班");
				} else if ("4".equals(mm)) 
				{
					course_type.append(i > 0 ? "、其他" : "其他");
				}
				i++;
			}
			i = 0;
			art.setCourse_type(course_type.toString());
			//授课对象
			StringBuffer students = new StringBuffer();
			for (String stu : art.getStudents().split("；")) 
			{
				if ("0".equals(stu)) 
				{
					students.append(i > 0 ? "、胎教" : "胎教");
				} else if ("1".equals(stu))
				{
					students.append(i > 0 ? "、幼儿园" : "幼儿园");
				} else if ("2".equals(stu)) 
				{
					students.append(i > 0 ? "、小学" : "小学");
				} else if ("3".equals(stu)) 
				{
					students.append(i > 0 ? "、初中" : "初中");
				} else if ("4".equals(stu)) 
				{
					students.append(i > 0 ? "、高中" : "高中");
				}
				i++;
			}
			i = 0;
			art.setStudents(students.toString());

			//开课时间
			StringBuffer time_type = new StringBuffer();
			for (String stu : art.getTime_type().split("；")) 
			{
				if ("0".equals(stu)) 
				{
					time_type.append(i > 0 ? "、随叫随到" : "随叫随到");
				} else if ("1".equals(stu)) 
				{
					time_type.append(i > 0 ? "、一周内" : "一周内");
				} else if ("2".equals(stu)) 
				{
					time_type.append(i > 0 ? "、两周内" : "两周内");
				} else if ("3".equals(stu)) 
				{
					time_type.append(i > 0 ? "、一个月内" : "一个月内");
				} else if ("4".equals(stu)) 
				{
					time_type.append(i > 0 ? "、上课中" : "上课中");
				} else if ("5".equals(stu))
				{
					students.append(i > 0 ? "、已结束" : "已结束");
				}
				i++;
			}
			i = 0;
			art.setTime_type(time_type.toString());
			//上课时间(星期)
			StringBuffer course_weeks = new StringBuffer();
			String[] arrweek=art.getCourse_week().split("");
			if(arrweek.length==8)
			{
				for(int j=1;j<8;j++)
				{
					if (1 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append("周一、");
						}
					} else if (2 == j) 
					{
						if ("0".equals(arrweek[j]))
						{

						} else 
						{
							course_weeks.append( "周二、");
						}
					} else if (3 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append( "周三、");
						}
					} else if (4 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append("周四、");
						}
					} else if (5 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append("周五、");
						}
					} else if (6 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append( "周六、");
						}
					} else if (7 == j) 
					{
						if ("0".equals(arrweek[j])) 
						{

						} else 
						{
							course_weeks.append("周日、");
						}
					}
					i++;
				}
				}else
				{
					course_weeks.append("全天候 ");
				}
			i = 0;
			art.setCourse_week(course_weeks.toString().substring(0, course_weeks.toString().length()-1)+"  ");	
			//上课时段（上午、中午、晚上）
			StringBuffer course_time=new StringBuffer();
			String[] arr_course_time=art.getCourse_time().split("");
			
			if(arr_course_time.length==4)
			{
				for(int j=1;j<4;j++)
				{		
					if (1 == j) 
					{
						if ("0".equals(arr_course_time[j])) 
						{

						} else 
						{
							course_time.append("上午、");
						}
					} else if (2 == j) 
					{
						if ("0".equals(arr_course_time[j])) 
						{

						} else 
						{
							course_time.append( "中午、");
						}
					} else if (3 == j) 
					{
						if ("0".equals(arr_course_time[j])) 
						{

						} else 
						{
							course_time.append( "晚上、");
						}					
					}
					i++;
				}
				}else{
					course_time.append("全天候 ");
				}
			i = 0;
			art.setCourse_time(course_time.toString().substring(0, course_time.toString().length()-1)+"  ");	
			//详细地址
			art.setArea(this.type(art.getArea()));			
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}

		return art;
	}

	public static void main(String[] args) 
	{
		String ss = "1011100、";
		System.out.println(ss.substring(0, ss.length()-1));		
	}
	
	//详细地址获取
	public String type(String str)
	{
		Map<String, String>map=new HashMap<String, String>();
			//江岸区
			map.put("0101","江岸一元");
			map.put("0102","江岸大智");
			map.put("0103","江岸车站");
			map.put("0104","江岸四唯");
			map.put("0105","江岸球场");
			map.put("0106","江岸西马");
			map.put("0107","江岸永清");
			map.put("0108","江岸劳动");
			map.put("0109","江岸台北");
			map.put("0110","江岸花桥");
			map.put("0111","江岸二七");
			map.put("0112","江岸新村");
			map.put("0113","江岸丹水池");
			map.put("0114","江岸后湖");
			map.put("0115","江岸塔子湖");
			map.put("0116","江岸谌家矶");
			map.put("0117","江岸经济开发区");
			//江汉区
			map.put("0201","江汉民族");
			map.put("0202","江汉民权");
			map.put("0203","江汉满春");
			map.put("0204","江汉花楼");
			map.put("0205","江汉水塔");
			map.put("0206","江汉前进");
			map.put("0207","江汉民意");
			map.put("0208","江汉新华");
			map.put("0209","江汉北湖");
			map.put("0210","江汉唐家墩");
			map.put("0211","江汉长青");
			map.put("0212","江汉万松");
			map.put("0213","江汉汉兴");
			map.put("0214","江汉江汉经济开发区");
			//硚口区
			map.put("0301","硚口易家墩");
			map.put("0302","硚口韩家墩");
			map.put("0303","硚口宗关");
			map.put("0304","硚口汉水桥");
			map.put("0305","硚口宝丰");
			map.put("0306","硚口古田");
			map.put("0307","硚口汉中");
			map.put("0308","硚口荣华");
			map.put("0309","硚口六角亭");
			map.put("0310","硚口汉正");
			map.put("0311","硚口长丰");
			map.put("0312","硚口开发区");
			//汉阳区
			map.put("0401","汉阳洲头");
			map.put("0402","汉阳晴川");
			map.put("0403","汉阳月湖");
			map.put("0404","汉阳翠微");
			map.put("0405","汉阳建桥");
			map.put("0406","汉阳鹦鹉");
			map.put("0407","汉阳五里墩");
			map.put("0408","汉阳琴断口");
			map.put("0409","汉阳六角亭");
			map.put("0410","汉阳永丰");
			map.put("0411","汉阳江堤");
			map.put("0412","汉阳经济开发区");
			//武昌区
			map.put("0501","武昌民族");
			map.put("0502","武昌民权");
			map.put("0503","武昌满春");
			map.put("0504","武昌花楼");
			map.put("0505","武昌水塔");
			map.put("0506","武昌前进");
			map.put("0507","武昌民意");
			map.put("0508","武昌新华");
			map.put("0509","武昌北湖");
			map.put("0510","武昌唐家墩");
			map.put("0511","武昌长青");
			map.put("0512","武昌万松");
			map.put("0213","武昌汉兴");
			map.put("0214","武昌");
			//青山区
			map.put("0601","青山红钢城");
			map.put("0602","青山新沟桥");
			map.put("0603","青山红卫路");
			map.put("0604","青山冶金");
			map.put("0605","青山钢花村");
			map.put("0606","青山青山");
			map.put("0607","青山武东");
			map.put("0608","青山白玉山");
			map.put("0609","青山厂前");
			map.put("0610","青山工人村");
			map.put("0611","江岸钢都管理委");
			//洪山区
			map.put("0701","洪山珞南");
			map.put("0702","洪山关山");
			map.put("0703","洪山梨园");
			map.put("0704","洪山狮子山");
			map.put("0705","洪山和平");
			map.put("0706","洪山洪山");
			map.put("0707","洪山张家湾");
			map.put("0708","洪山青菱");
			map.put("0709","洪山卓刀泉");
			map.put("0710","洪山天兴乡");
			//东西湖
			map.put("0801","东西湖吴家山");
			map.put("0802","东西湖走马岭");
			map.put("0803","东西湖新沟");
			map.put("0804","东西湖长青");
			map.put("0805","东西湖慈惠");
			map.put("0806","东西湖泾河");
			map.put("0807","东西湖金银湖");
			map.put("0808","东西湖将军路");
			map.put("0809","东西湖东山");
			map.put("0810","东西湖柏泉");
			map.put("0811","东西湖辛安渡");
			map.put("0812","东西湖常青花园新区");
			//汉南区
			map.put("0901","汉南纱帽");
			map.put("0902","汉南湘口");
			map.put("0903","汉南汉南农场");
			map.put("0904","汉南银莲湖农场");
			map.put("0905","汉南东荆");
			map.put("0906","汉南乌金农场");
			map.put("0907","汉南东城垸农场");
			map.put("0908","汉南邓南");
			map.put("0909","汉南开发区");
			//江夏
			map.put("1001","江夏纸坊");
			map.put("1002","江夏金口");
			map.put("1003","江夏郑店");
			map.put("1004","江夏乌龙泉");
			map.put("1005","江夏法泗");
			map.put("1006","江夏安山");
			map.put("1007","江夏湖泗");
			map.put("1008","江夏五里界");
			map.put("1009","江夏山坡乡");
			map.put("1010","江夏舒安乡");
			map.put("1011","江夏梁子湖风景区");
			map.put("1012","江夏金水");
			map.put("1013","江夏庙山");
			map.put("1014","江夏藏龙岛");
			map.put("1015","江夏大桥新区");
			//蔡甸区
			map.put("1101","蔡甸蔡甸");
			map.put("1102","蔡甸张湾");
			map.put("1103","蔡甸侏儒");
			map.put("1104","蔡甸永安");
			map.put("1105","蔡甸奓山");
			map.put("1106","蔡甸大集");
			map.put("1107","蔡甸索河");
			map.put("1108","蔡甸玉贤");
			map.put("1109","蔡甸消泗乡");
			map.put("1110","蔡甸桐湖");
			map.put("1111","蔡甸军山");
			map.put("1112","蔡甸沌口");
			//黄陂区
			map.put("1201","黄陂三里");
			map.put("1202","黄陂横店");
			map.put("1203","黄陂六指");
			map.put("1204","黄陂蔡店乡");
			map.put("1205","黄陂滠口");
			map.put("1206","黄陂大潭");
			map.put("1207","黄陂祁家湾");
			map.put("1208","黄陂蔡家榨");
			map.put("1209","黄陂李家集");
			map.put("1210","黄陂长轩岭");
			map.put("1211","黄陂姚家集");
			map.put("1212","黄陂罗汉寺");
			map.put("1213","黄陂木兰乡");
			map.put("1214","黄陂前川");
			map.put("1215","蔡甸王家河");
			map.put("1216","蔡甸武湖 ");
			map.put("1217","蔡甸天河");
			map.put("1218","蔡甸木兰山风景管理区");
			map.put("1219","蔡甸盘龙城经济发展区");
			//新洲区
			map.put("1301","新洲邾城");
			map.put("1302","新洲旧");
			map.put("1303","新洲潘塘");
			map.put("1304","新洲阳逻");
			map.put("1305","新洲双柳");
			map.put("1306","新洲三店");
			map.put("1307","新洲仓埠");
			map.put("1308","新洲汪集");
			map.put("1309","新洲李集");
			map.put("1310","新洲徐古");
			map.put("1311","新洲凤凰");
			map.put("1312","新洲辛冲");
			if(map.get(str)!=null)
			{
				return map.get(str);
			}else
			{				
				return "洪山街道口";
			}
	}
	
	public IReadNewService getiReadNewService() {
		return iReadNewService;
	}

	public void setiReadNewService(IReadNewService iReadNewService) {
		this.iReadNewService = iReadNewService;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public Article getArt() {
		return art;
	}

	public void setArt(Article art) {
		this.art = art;
	}

	public String getId() {
		return id;
	}


}
